<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
      *{
        margin:0px;
        padding: 0px;
    }  
    table{
        border-collapse: collapse;
    }
    td{
       
        width: 100px;
        height: 40px;
    }
    </style>
    
</head>

<body>
<thead>
    <table id="mytable" border="1px";>

<script>
    var arr=[{name:"jake",age:18,gender:"男"},{name:"rose",age:18,gender:"女"},{name:"mary", age:24,gender:"女"},{name:"mary", age:24,gender:"女"}]
    var tHead=document.getElementById("mytable");
    var str1="";
    var str2="";
    for(var key in arr[0]){
            str2+=`<td>${key}</td>`
        }
        str1='<thead >'+str2+'</thead>'
        str2="";//初始化表头
    for(var i=0;i<arr.length;i++){
        for(var key in arr[i]){
           str2+= `<td>${arr[i][key]}</td>`;
        }
       str1+='<tr  >'+str2+'</tr>'
        str2="";
    }
    tHead.innerHTML=str1;
</script>
</body>
</html>